Skip to content

Video: fix decode/encode defects (VK, D3D12, shared, validation) - #264

Merged
dzhdanNV merged 19 commits into
NVIDIA-RTX:mainfrom
Daedie-git:fix/video-defects
Oct 22, 2026
Merged

dzhdanNV merged 19 commits into
NVIDIA-RTX:mainfrom
Daedie-git:fix/video-defects

Conversation

@Daedie-git

@Daedie-git Daedie-git commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes for defects in the video decode/encode implementation (#226). I found them in a review of main @ d0e1cbf3. Each defect below was reproduced on the unchanged tree by a failing unit test or a GPU probe. After the fix, the same test or probe passes. The probe sources are kept outside the repo; I can share them.

Stacked follow-up: #265 (NVIDIA driver workaround for encode feedback; depends on this PR).

Public API changes (additive)

  • TextureUsageBits::VIDEO_OUTPUT_ONLY: decode output or encode input that is never a DPB picture. Some drivers require separate DPB images (RADV reports SEPARATE_REFERENCE_IMAGES and rejects DECODE_DST|DECODE_DPB).
  • VideoH264SequenceParameterSetBits::FRAME_CROPPING + frameCrop*Offset: without cropping, a 1080p H.264 stream signalled 1088 lines.
  • VideoH265EncodePictureDesc (VideoEncodeDesc::h265PictureDesc): selects VPS/SPS/PPS ids for encode. Before, they were hardwired to 0.
  • VideoAV1DecodePictureDesc::skipModeFrames.
  • VideoAV1EncodeDecodeInfoDesc::pictureDesc / av1PictureDesc: the submitted values, used by the metadata-only (no payload header) path.
  • Documented: H.265 generalLevelIdc is in bitstream units (30 × level). An H.264 frame reference sets neither or both field flags.

Fixes

Vulkan

Defect Observed before
Non-reference decode passes pSetupReferenceSlot with slotIndex = -1 VUID-VkVideoDecodeInfoKHR-pSetupReferenceSlot-07168
Rate-control changes after the first encode never applied (no vkCmdControlVideoCodingKHR) VUID-vkCmdBeginVideoCodingKHR-pBeginInfo-08254
CBR/VBR pass a nonzero constantQp VUID-vkCmdEncodeVideoKHR-constantQp-08269/08272
H.265 encode always uses parameter-set id 0 VUID-...-08231/08232/08233, EndCommandBuffer fails
H.265 general_level_idc cast straight to StdVideoH265LevelIdc; wrong default level for 4K invalid enum (e.g. 90), 3840×2160 defaulted to 4.1
H.265 decode slice offsets +4 land on the NAL header every P frame decoded as a copy of the IDR (~22 dB). Now bit-exact
H.265 decode RPS not sorted by POC reversed caller order: frames 2–7 at ~21 dB. Now bit-exact
H.264 encode never sets num_ref_idx_active_override_flag 2 refs requested, 1 used
AV1 decode: EIGHTTAP/ONLY_4X4 (0) silently became SWITCHABLE/SELECT; OrderHints/expectedFrameId indexed by DPB index instead of reference name; SkipModeFrame never set; setup SavedOrderHints wrong unit test on StdVideoDecodeAV1*
AV1 encode update_ref_delta/update_mode_delta never set deltas never signalled
GetTextureMemoryDesc2 omits the video profile list RADV segfaults in vkGetDeviceImageMemoryRequirements
Decode usage fixed to DST|DPB and caps probed with that combination every decode profile reported UNSUPPORTED on RADV. Now advertised as distinct mode, bit-exact

D3D12

Defect Observed before
Legacy barriers transition only plane 0 of an NV12/P010 array layer debug layer id 538 on the chroma plane
Decode bitstream offset alignment advertised as 1 debug layer id 1110, Close() E_INVALIDARG
AV1 key frames send RefreshFrameFlags = 0 when maxReferenceNum = 0 debug layer id 1306
AV1 encode ignores driver RequiredFeatureFlags (frame segmentation auto) every default AV1 encode failed on RTX 4070 (id 1306)
AV1 decode: interp_filter/tx_mode 0 remapped; filter_intra never set; order_hint_bits nonzero without order hints; warped_motion from the sequence flag captured DXVA_PicParams_AV1
AV1 uniform tile layout without size arrays null dereference (access violation)
Metadata-only AV1 decode info: wrong order hint and refresh flags; tile offset counted twice value mismatch; 128 vs 64
Rate control: QP range / max frame size / VBV / initial QP filled in but their flags never set Flags = 0, so the driver ignored the limits
H.264 frame references get UsedForReferenceFlags = 0 frames 2–7 at ~21 dB. Now bit-exact
H.265: RPS not sorted; flat scaling lists instead of spec defaults ~21 dB / ~43 dB. Now bit-exact

Shared / Validation

  • AV1 header reconstruction (GetEncodeDecodeInfoFromHeader). It returned SUCCESS with wrong decode info for: frame ids, separate U/V delta Q, monochrome, 128×128 superblocks, loop restoration (Remap_Lr_Type, unit shifts), multi-tile OBU_FRAME (missing byte_alignment), skip mode and warped motion, superres, and frame-size override. It has been rewritten as a single frame-header parser that follows the spec order. Unsupported syntax is now rejected. Checked against ffmpeg trace_headers on 63 frames, with 0 mismatching fields; randomized searches show 0 silent errors.
  • Validation: encode-feedback readback buffers must be CPU-visible. Before, both backends dereferenced nullptr + offset: Release crashed, Debug asserted. Also added checks for the new API fields.

Second review

Fixes from a second review, folded into the per-area commits. Each was reproduced first:

Change Before
Vulkan H.264 decode: a frame reference may set both TOP_FIELD and BOTTOM_FIELD (as documented); Vulkan now clears both std field flags RADV + VVL: 07260, 07150, 07267, 07268
D3D12 barriers: PlaneBits::COLOR on NV12/P010/P016 covers all planes, on both legacy and enhanced barriers debug layer id 538 (legacy, chroma left untransitioned) / 1334 (enhanced, luma left untransitioned)
Contract: AV1 encode txMode = 0 selects the backend default on both backends; Vulkan used to send ONLY_4X4 for lossy frames invalid native value; the backends disagreed
Contract / Validation: the decode setup slot (and the encode reconstructedSlot) must not be one of the current references. Vulkan always writes the setup slot (VUID-vkCmdDecodeVideoKHR-pDecodeInfo-08376), so a non-reference picture needs a slot whose picture is no longer needed NVIDIA: non-reference B frames corrupted (11–34 dB); RADV: 07176, then 07239/07266 on the next frame
Docs: VideoAV1DecodePictureDesc::orderHints is indexed by reference frame name —

AV1 follow-up

Change Before
Validation bounds distinct AV1 reference slots by maxReferenceNum, not name entries (names may share a slot) a legal 7-names-on-1-slot layout was rejected. This includes GetVideoAV1EncodeDecodeInfo's own output whenever maxReferenceNum < 7
VK AV1 encode no longer forces seq_force_screen_content_tools = 0 in the driver's sequence header NRI's default stream was undecodable: the frame headers didn't match the header WriteVideoAV1ObuHeaders writes (ffmpeg: zero_bit out of range). Now ffmpeg and dav1d decode it at 44.7 dB
Contract: if the driver overrides the AV1 sequence header so it no longer matches what WriteVideoAV1ObuHeaders writes, CreateVideoSessionParameters returns UNSUPPORTED NVIDIA rewrites seq_force_screen_content_tools = 1 to 0, so the stream was silently undecodable
Validation requires all 7 AV1 reference names (LAST..ALTREF) for inter frame decode; inter frames always code ref_frame_idx for every name. Encode is unchanged (names may be left unset) a 2-of-7 decode layout passed validation, then the NVIDIA driver crashed inside vkCmdDecodeVideoKHR

Station testing fixes

Found while testing on NVIDIA 615.71 (Linux, RTX 3080) and 617.42 (Windows, RTX 3070), Vulkan and D3D12:

Change Before
D3D12 encode: the GOP structure follows the application's SPS every D3D12 encode failed
D3D12 encode: num_ref_idx_active_override_flag is requested when the active references differ from the PPS defaults extra references dropped
VK decode: picture structures stay alive until the command buffer is re-recorded NVIDIA 610 crash in vkQueueSubmit2 (H.264, 3+ refs)
VK encode: the setup slot is passed for non-reference pictures VUID-vkCmdEncodeVideoKHR-pEncodeInfo-08377-class errors
VK encode: CBR/VBR always pass a QP range; omitted bounds use the implementation's codec range, explicit bounds are clamped NVIDIA ignored the bitrate; Intel ANV VUID-...-useMinQp-08286
VK H.264 decode: slice offsets point at the start code NVIDIA decode errors
VK: IDR pictures don't set no_output_of_prior_pics_flag earlier pictures waiting for output were dropped
Shared AV1: CDEF secondary strengths are passed as coded wrong CDEF on decode
Validation: GetVideoPictureState accepts DPB roles for coincide decode output valid decodes rejected
Validation: encode requires reconstructedPicture in sessions with DPB slots VUID-vkCmdEncodeVideoKHR-pEncodeInfo-08377 at submit

Review follow-ups

From a second adversarial review of this branch; each was verified in code first:

Change Before
VK decode caps: supported if coincide (combined usage) or distinct (output-only and DPB-only); encode accepts separate SRC/DPB images a coincide-only driver (e.g. ANV) reported every decode profile UNSUPPORTED
VK AV1 decode: tile arrays are copied into the persisted storage; omitted arrays under uniform spacing are derived from the frame size tile pointers aliased app memory; null arrays with TileCols > 1
VK H.265 encode: num_ref_idx_active_override_flag compares with the PPS defaults (as H.264) PPS default 2 with one reference: no override, decoder assumed two
D3D12 CBR/VBR: default qpMax per codec (AV1 255, else 51) AV1 with only qpMin = 100 gave min > max
D3D12 AV1 metadata-only info: no references means key frame; txMode and picture flags follow what was encoded forced key frame failed reconstruction; TX_MODE_SELECT reported for LARGEST
VK AV1: sequence-header override check compares the fields that affect frame headers (new parser) instead of bytes; GOP-remaining info added to the rate-control scope harmless driver changes (level, padding) caused UNSUPPORTED
Validation: H.265 generalLevelIdc (0 or a Table A.8 value), CDEF strengths, txMode, interpolationFilter ranges; D3D12 reports an error when the num-ref override is needed but unsupported invalid values reached the driver

Verification

Tests are not part of this PR; they live on the author's fork. Results below are for this branch on upstream a48ef101 plus the fork-only tests.

  • Linux, Vulkan: RTX 3080, NVIDIA 615.71.09, Khronos validation 1.4.357. ctest (video-short, hardware, traceability, fuzz/stress/soak) in Release and Debug; sample matrix 50 pass / 0 fail / 27 skip; 14/14 SVT-AV1 streams plus 6 libaom tile-layout streams bit-exact; 0 validation errors.
  • Windows, Vulkan + D3D12: RTX 3070, NVIDIA 617.42, D3D12 debug layer and Vulkan validation. ctest Release and Debug; D3D12 (legacy and enhanced barriers) 47 pass / 5 fail / 25 skip, Vulkan 50 / 0 / 27; 16/16 AV1 streams bit-exact; 0 validation errors.
  • Every decode dump is bit-exact against ffmpeg (the 5 D3D12 failures excepted); decoded frames checked visually for H.264, H.265 and AV1 on both APIs.
  • The 5 D3D12 failures are an NVIDIA driver defect: H.265 slice headers omit the reference list modification.
  • Builds: VK/D3D12, Debug/Release, with and without Agility.

Driver issues found (not NRI)

  • NVIDIA D3D12 H.265: no list modification in slice headers; heights that aren't multiples of 32 corrupt the bottom CTB row; maxFrameBits is ignored.
  • NVIDIA Vulkan H.265 ignores qpMin/qpMax (NRI fills the layer info as for H.264; validation is clean). NVIDIA 580 (Linux) had the list-modification bug too; 615 fixes it.

Not covered

  • AV1 encode on hardware (no available GPU supports it), including the D3D12 metadata-only path; the AV1 encode fixes above were verified through unit tests and, on the RTX 4070, D3D12 encode earlier.
  • Distinct decode output / separate DPB images (NVIDIA doesn't support them), AMD and Intel hardware in this round.
  • D3D12 rate-control / GOP change signalling (RATE_CONTROL_CHANGE, GOP_SEQUENCE_CHANGE) is not implemented.

Known, not addressed here

  • D3D12 dpbTextureArrayRequired: not derived from decode tier 1 or REQUIRE_TEXTURE_ARRAYS. I couldn't reproduce this (the RTX 4070 is tier 2).
  • RADV: VVL 06811/07142 fire on video images that carry TRANSFER usage, even though the driver reports that usage as supported. This looks like a RADV/VVL inconsistency; decode output is correct.
  • D3D12 max frame size: skipped when the encoder doesn't support it, and there is no capability field to report this.
  • AV1 frame size: VideoAV1DecodePictureDesc has no per-frame size, so a frame-size override or superres needs a matching picture size.

🤖 Generated with Claude Code

@dzhdanNV

dzhdanNV commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this! I do want to add a video sample using yours as the baseline, but I have been postponing this due to other tasks. This PR is marked "as draft", ping me when it's ready to merge, please.

@Daedie-git

Copy link
Copy Markdown
Contributor Author

Thanks for this! I do want to add a video sample using yours as the baseline, but I have been postponing this due to other tasks. This PR is marked "as draft", ping me when it's ready to merge, please.

Hey. I've been setting up a little cluster of machines at work with multiple GPUs and windows/linux mix. To be able to test en develop things in parallel. So I thought this would be a good time to have some of the powerful new models comb through the implementation for spec violations and try to break the implementation against it.

I want to have a closer look myself and also test it in the Sample application before I take it out of Draft. :)

@Daedie-git
Daedie-git marked this pull request as ready for review October 15, 2026 06:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T06:16:49.697024Z f3e4a82 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Daedie-git

Copy link
Copy Markdown
Contributor Author

It's ready for review

@Daedie-git

Copy link
Copy Markdown
Contributor Author

Sample is also updated to match

Copy link
Copy Markdown
Collaborator

Two independent reviewers reviewed a48ef10184e3cb434faec7cda1ec76a9574c354d → 3e7b8492fb490e13d872ff48317b8d3f325766e8. Both report NoGo / FAIL for one introduced contract bug. API changes are acceptable for this WIP interface; existing functionality gaps are recorded separately and do not control the verdict.

Reviewer Focus Verdict
1 Vulkan, lifetimes, resource usage NoGo
2 D3D12, shared AV1 parser, Validation NoGo

P2 blocker: accepted H.265 “unspecified” level becomes an invalid Vulkan enum

VideoHelpersVK.h:251 converts generalLevelIdc = 0 to STD_VIDEO_H265_LEVEL_IDC_INVALID. However, the public contract explicitly permits zero as “unspecified,” and Validation accepts it.

Custom H.265 VPS/SPS descriptors reach this conversion unchanged through VideoSessionParametersVK.hpp; only absent parameter descriptions receive concrete defaults. A supported NRI input therefore reaches Vulkan with invalid native data. The base revision converted zero to the valid native level-1.0 enum.

The Vulkan H.265 parameter-set specification specifies concrete STD_VIDEO_H265_LEVEL_IDC_<major>_<minor> values for the profile-tier-level structures, for both decode and encode.

Suggested correction: resolve zero to an appropriate concrete default before native conversion, or remove the zero allowance and reject it in Validation.

A focused executable using the unchanged target’s actual headers confirmed:

level 0 -> 2147483647 (INVALID)
level 120 -> 5 (LEVEL_4_0)

Runtime qualification: a public-NRI probe on an RTX 4080, with NRI Validation and Vulkan validation enabled, successfully created H.265 decode parameters with both zero and explicit levels, with no validation errors. No driver failure was reproduced. This finding is a confirmed native-data contract violation tolerated by the tested implementation.

Follow-up gaps — non-blocking for this PR

These can be addressed separately:

  • D3D12 distinct decode output/DPB: remains unsupported and correctly advertises false (VideoHelpersD3D12.h:43).
  • AV1 segmentation: Vulkan encode rejects segmentation (CommandBufferVK.hpp:1173); D3D12 encode rejects explicit segmentation (CommandBufferD3D12.hpp:1573).
  • AV1 film-grain decode: remains unsupported and rejected by Validation (CommandBufferVal.hpp:392).
  • AV1 payload-header reconstruction: intentionally rejects state-dependent paths including short reference signaling, reference-derived frame sizes, segmentation, nonidentity global motion, film grain, error-resilient inter frames, and inherited loop-filter deltas (SharedVideo.h:1065).

Verification

  • Debug and Release builds passed with D3D12, Vulkan, D3D11, WGPU, NONE, and Validation enabled.
  • D3D12 builds passed with Agility and without Agility; the latter selected the actual Windows SDK 10.0.20348 headers.
  • Build logs contained no MSVC warnings or errors.
  • git diff --check passed, and all 29 changed files use CRLF.
  • Focused host conversion test and RTX 4080 parameter-creation probe completed.
  • Full codec-output GPU testing was not performed.

Result: 1 blocker, 4 follow-up gap groups. Resolve the level-zero contract before merging; no other introduced blocker was confirmed.

@dzhdanNV

dzhdanNV commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Please, fix the VK bug and optionally some follow-up gaps. Also, assuming this is merged, is #265 ready for a review?

[EDITED] I got it - we need to merge this one to rebase #265 and make it reviewable.

@dzhdanNV

dzhdanNV commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Just asking - are you OK to fix minor issues mentioned above? If not, let me know, I will merge and do some fixes on top. This one is a blocker for #265, which in order is a blocker for NVIDIA-RTX/NRISamples#27. Of course, I would like to merge and see video goodness in action as soon as possible. Moreover, it's needed for some of my tasks.

@Daedie-git

Copy link
Copy Markdown
Contributor Author

Sorry, I missed your prior comments. Hectic days.
I will address them, no problem.

@Daedie-git

Copy link
Copy Markdown
Contributor Author

Fixed the H.265 level-0 blocker by taking option 2: Validation now rejects generalLevelIdc = 0 for session parameters and for the Annex-B parameter-set writer, and the header no longer documents 0 as "unspecified" (8f15819, c009681). Tested on Windows (RTX 5080) and Linux (RTX 3080), including real-device H.265 session parameters at every Table A.8 level with Vulkan validation enabled.

H.264 levelIdc = 0 has the same native mapping issue. I'm including that in the next commit.

@Daedie-git

Copy link
Copy Markdown
Contributor Author

done

BjornSAIM and others added 13 commits October 21, 2026 13:33
- TextureUsageBits::VIDEO_OUTPUT_ONLY for decode outputs / encode inputs
  that never act as DPB pictures (drivers requiring separate DPB images)
- H.264 SPS frame cropping (FRAME_CROPPING + crop offsets)
- VideoH265EncodePictureDesc to select VPS/SPS/PPS ids on encode
- VideoAV1DecodePictureDesc::skipModeFrames
- VideoAV1EncodeDecodeInfoDesc::pictureDesc/av1PictureDesc for the
  metadata-only (no payload header) reconstruction path
- documented H.265 generalLevelIdc units and H.264 frame reference flags
- documented AV1 encode txMode 0 (backend default), AV1 decode orderHints indexing
  and the decode setup slot contract

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- reject encode feedback readback buffers that are not CPU-visible
  (track MemoryLocation on BufferVal for bound, committed and placed buffers)
- VIDEO_OUTPUT_ONLY textures: require a video usage, forbid combining with
  VIDEO_REFERENCE_ONLY, forbid reference pictures and coincident DPB setup
- H.264 SPS frame cropping range checks (session parameters, Annex-B writer)
- H.265 encode VPS/SPS/PPS selection must exist in the session parameters
- AV1 decode SKIP_MODE_PRESENT requires valid, referenced skipModeFrames
- AV1 encode decode-info: require pictureDesc/av1PictureDesc and a CPU-visible
  readback buffer when no payload header is provided
- decode setup slot / encode reconstructed slot must not be a current reference
- AV1: bound distinct reference slots (names may share a slot); require all 7
  reference names for inter frame decode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AV1 GetEncodeDecodeInfoFromHeader (single spec-ordered frame header parser
replacing the separate key/inter parsers):
- read delta_frame_id_minus_1 per reference; allow_high_precision_mv gated on
  force_integer_mv
- quantization: NumPlanes (mono_chrome), diff_uv_delta and V deltas; NumPlanes
  gating for loop filter, CDEF and loop restoration
- 128x128 superblocks in tile info and single-tile layouts
- loop restoration: Remap_Lr_Type, lr_unit_shift/lr_uv_shift, USES_LR flags
- byte_alignment before the tile group of an OBU_FRAME
- inter tail order: reference mode, skip mode (fills skipModeFrames),
  allow_warped_motion, reduced_tx_set, global motion
- superres MiCols from the downscaled width; intrabc only without superres
- honor key-frame frame size override; parse delta_lf params
- reject film grain with apply_grain, reduced still picture headers and
  nonzero byte-alignment padding
- keep enable_ref_frame_mvs/enable_jnt_comp consistent without order hints

Annex-B writer: H.264 SPS frame cropping; reject invalid frame id lengths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- decode: always pass the validated setup slot when the session has DPB
  slots (VUID-VkVideoDecodeInfoKHR-pSetupReferenceSlot-07168)
- decode H.265: slice segment offsets point at the 3-byte start code
  (+1 instead of +4); sort StCurrBefore/StCurrAfter by POC
- encode: track rate control state and apply changes with
  vkCmdControlVideoCodingKHR (VUID-...-08254); constantQp only for CQP
  (08269/08272)
- encode H.265: select VPS/SPS/PPS ids from h265PictureDesc (08231-08233);
  convert generalLevelIdc from bitstream units to StdVideoH265LevelIdc and
  pick spec-correct default levels
- encode H.264: num_ref_idx_active_override_flag; SPS frame cropping
- AV1 decode: pass interpolation filter and tx mode through, OrderHints and
  expectedFrameId by reference name, SkipModeFrame, setup SavedOrderHints
  from the current frame's OrderHints
- AV1 encode: signal loop filter ref/mode delta updates
- GetTextureMemoryDesc2: chain the video profile list like texture creation
  (RADV crashed without it)
- VIDEO_OUTPUT_ONLY usage (DST/SRC only); query DST and DPB usage separately
  and report coincide/distinct decode modes from the driver (fixes decode
  being reported unsupported on RADV)
- encode feedback: fail instead of dereferencing an unmapped buffer
- H.264 decode: a frame reference with both field flags has no std field flags
- AV1 encode: txMode 0 keeps the default; keep the app's seq_force_screen_content_tools
  and fail with UNSUPPORTED if driver overrides change the sequence header that
  WriteVideoAV1ObuHeaders writes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- legacy barriers: per-layer/mip barriers on planar formats (NV12/P010/P016)
  transition every plane (debug layer id 538)
- decode: advertise D3D12_VIDEO_DECODE_MIN_BITSTREAM_OFFSET_ALIGNMENT
  (debug layer id 1110)
- AV1 decode: pass interp_filter and tx_mode through, filter_intra from the
  sequence, order_hint_bits 0 without order hints, warped_motion from the
  frame flag, derive tile sizes for uniform layouts without size arrays
  (null dereference)
- AV1 encode: key frames always refresh 0xFF; set driver-required picture
  control flags (frame segmentation auto, force integer MV); pass explicit
  interpolation filter / CDEF damping values through
- AV1 metadata-only decode info: frame type, order hint, refresh flags,
  frame id and interpolation filter from the submitted picture desc;
  bitstreamOffset relative to encodedBitstreamOffset
- rate control: enable QP range, initial QP, max frame size and VBV flags
  when values are supplied and supported by the encoder
- H.264 decode: UsedForReferenceFlags = 3 for frame references
- H.265 decode: sort StCurrBefore/StCurrAfter by POC; spec default scaling
  lists when enabled without list data
- H.265 encode: PPS id from h265PictureDesc
- encode feedback: don't read unmapped buffers; null-check descs
- barriers: PlaneBits::COLOR on multi-planar formats covers all planes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e output pictures

CmdDecodeVideo accepts a DECODE_OUTPUT picture (not OUTPUT_ONLY) as a decode
reference or setup picture, GetVideoPictureState rejected the same roles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A session with DPB slots requires pSetupReferenceSlot for every encode
(VVL: pSetupReferenceSlot is NULL but the session was created with maxDpbSlots).
B frames and AV1 pictures with refreshFrameFlags = 0 passed none. The std
is_reference flag still follows the frame type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…buffer is re-recorded

NVIDIA (610.57.04) reads the chained codec picture structures after
vkCmdDecodeVideoKHR returned: H.264 decode with 3 or more references crashed
in vkQueueSubmit2 (null pointer in the driver, depends on the stack contents).
The structures and arrays chained into the decode command now live in
per-command-buffer storage, released by Begin and the destructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NVIDIA (610.57) ignored the bitrate without it: 8 H.264 frames took 4045 bytes
for 300 and 80000 kbit/s alike, with the range they take 16 KB and 481 KB.
qpMin/qpMax were ignored by the Vulkan backend (D3D12 applies them), the
default is the full codec range. A QP range change is a rate control change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The offsets landed on the NAL header (+4 of the documented 4-byte start code),
H.265 was fixed to +1 already. NVIDIA 580.142 (RTX 3080) decoded every H.264
picture as garbage (4.8 dB), ffmpeg decodes the same stream at 43.6 dB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The header parser stored cdef_y/uv_sec_strength with the AV1 3 -> 4
adjustment applied. Vulkan expects the coded value 0..3 and adjusts it
itself: NVIDIA 580.142 decoded SVT-AV1 streams with luma errors of up to 3
in every picture that has a coded strength of 3 (bit-exact once the coded
value is passed).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The driver writes the slice headers with log2_max_frame_num, pic_order_cnt_type and log2_max_pic_order_cnt_lsb from the GOP structure, which was hardwired to 0, so a SPS with other values (as the Vulkan path accepts) produced undecodable streams.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ences differ from the PPS defaults

The driver writes slice headers without the override flag unless it is requested, so P pictures with more than one reference (and B pictures) decoded with the wrong list sizes. The H.265 active counts are passed as well.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude and others added 6 commits October 21, 2026 13:33
H.264/H.265 encode set no_output_of_prior_pics_flag on every IDR. With
reordered B pictures, a conformant decoder (ffmpeg) then dropped the last
pictures before the IDR (2 of 20 frames of a BBBP stream with idr period 7).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The NVIDIA workaround passed 0/51 (AV1 1/255) when qpMin/qpMax were omitted.
That leaves the advertised capability range (Intel ANV: minQp 10,
VUID useMinQp-08286). Keep the queried minQp/maxQp (H.264/H.265) and
minQIndex/maxQIndex (AV1) on the session, use them for omitted bounds and
clamp explicit bounds to them. The range is still always enabled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… slots

reconstructedPicture is documented as required when maxReferenceNum > 0, also
for non-reference pictures (B, AV1 refreshFrameFlags = 0), but a null one was
forwarded and the Vulkan backend then passed no setup slot
(VUID-vkCmdEncodeVideoKHR-pEncodeInfo-08377). This replaces the AV1-only
check. Sessions without DPB slots are unchanged. Adds VID-REG-031 and the
missing pictures in three existing validation tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Zero is not a level and has no native Vulkan enum (it became STD_VIDEO_H265_LEVEL_IDC_INVALID), and the Annex B writer would code it as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like H.265 level 0, H.264 levelIdc 0 (and level 1b, coded as 9) has no native Vulkan level and became STD_VIDEO_H264_LEVEL_IDC_INVALID; the Annex B writer would code it as is. Both session parameters and the validated Annex B writer now reject it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dzhdanNV

Copy link
Copy Markdown
Collaborator

Merged. Thanks for your stellar work!

@dzhdanNV
dzhdanNV merged commit 2bbf392 into NVIDIA-RTX:main Oct 22, 2026
dzhdanNV added a commit that referenced this pull request Oct 22, 2026
VK: work around NVIDIA encode feedback query copy hang (stacked on #264)
dzhdanNV added a commit that referenced this pull request Oct 22, 2026
D3D12: fix H.265 encode reference lists (stacked on #264)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants